﻿<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 

class LogsApp extends BaseApp
{
    function adminlogs()
    {
		$page = $_GET['page'];
	    if(!$page){
		    $page=1;
	    }
        $_GLOBAL['page'] = $page ;		
	    @include(ROOT_PATH."/data/logs/admin_logs.php");

	    $rows=20;
	    $min=($page-1)*$rows;
	    $max=$min+$rows;
	    $total=count($logdb);
	    $showpage=getpage("","","index.php?app=logs&act=adminlogs",$rows,$total);
	    for($i=$min;$i<$max;$i++){
		    if(!$logdb[$i]){
			    break;
		    }
		    list($rs[uid],$rs[username],$rs[posttime],$rs[ip],$rs[fromurl],$rs[weburl])=explode("\t",$logdb[$i]);
		    $rs[posttime]=date("Y-m-d H:i:s",$rs[posttime]);
		    $rs[id]=$i;
		    $listdb[]=$rs;
	    }

        $this->assign('showpage', $showpage);		
        $this->assign('data', $listdb);	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('adminlogs_list.view.php');
    }

    function adminlogsdel()
    {
		
	    $id = $_GET['id'];
    $iddb[$id] = $id;		
	if(!$iddb){
		echo("请选择一条");
	}
	unset($logdb);
	@include(ROOT_PATH."/data/logs/admin_logs.php");
	$writefile="<?php	\r\n";
	for($i=0;$i<count($logdb);$i++){
		if(!$iddb[$i]){
			$writefile.="\$logdb[]=\"$logdb[$i]\";\r\n";
		}else{
		}
	}
	write_file(ROOT_PATH."/data/logs/admin_logs.php",$writefile);
    	$this->adminlogs();
		
    }

    function adminloginlogs()
    {
		$page = $_GET['page'];
	    if(!$page){
		    $page=1;
	    }
        $_GLOBAL['page'] = $page ;		
	    @include(ROOT_PATH."/data/logs/adminlogin_logs.php");

	    $rows=20;
	    $min=($page-1)*$rows;
	    $max=$min+$rows;
	    $total=count($logdb);
	    $showpage=getpage("","","index.php?app=logs&act=adminloginlogs",$rows,$total);
	    for($i=$min;$i<$max;$i++){
		    if(!$logdb[$i]){
			    break;
		    }
		    list($rs[username],$rs[password],$rs[posttime],$rs[ip])=explode("\t",$logdb[$i]);
		    $rs[posttime]=date("Y-m-d H:i:s",$rs[posttime]);
		    $rs[id]=$i;
		    $listdb[]=$rs;
	    }	
        $this->assign('showpage', $showpage);		
        $this->assign('data', $listdb);	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('adminloginlogs_list.view.php');
    }

    function adminlogindel()
    {
		
	    $id = $_GET['id'];
    $iddb[$id] = $id;	
	if(!$iddb){
		echo("请选择一条");
	}
	unset($logdb);
	@include(ROOT_PATH."/data/logs/adminlogin_logs.php");
	$writefile="<?php	\r\n";
	for($i=0;$i<count($logdb);$i++){
		if(!$iddb[$i]){
			$writefile.="\$logdb[]=\"$logdb[$i]\";\r\n";
		}else{
		}
	}
	write_file(ROOT_PATH."/data/logs/adminlogin_logs.php",$writefile);
    	$this->adminloginlogs();
		
    }


	
}

/**
*分页
**/
function getpage($table,$choose,$url,$rows=20,$total=''){
	global $page,$db;
	if(!$page){
		$page=1;
	}
	//当存在$total的时候.就不用再读数据库
	if(!$total && $table){
		$query=$db->get_one("SELECT COUNT(*) AS num  FROM $table $choose");
		$total=$query['num'];
	}
	$totalpage=@ceil($total/$rows);
	$nextpage=$page+1;
	$uppage=$page-1;
	if($nextpage>$totalpage){
		$nextpage=$totalpage;
	}
	if($uppage<1){
		$uppage=1;
	}
	$s=$page-3;
	if($s<1){
		$s=1;
	}
	$b=$s;
	for($ii=0;$ii<6;$ii++){
		$b++;
	}
	if($b>$totalpage){
		$b=$totalpage;
	}
	for($j=$s;$j<=$b;$j++){
		if($j==$page){
			$show.=" <a href='#'><font color=red>$j</font></a>";
		}else{
			$show.=" <a href=\"$url&page=$j\" title=\"第{$j}页\">$j</a>";
		}
	}
	$showpage="<a href=\"$url&page=1\" title=\"首页\">首页</A> <a href=\"$url&page=$uppage\" title=\"上一页\">上一页</A>  {$show}  <a href=\"$url&page=$nextpage\" title=\"下一页\">下一页</A> <a href=\"$url&page=$totalpage\" title=\"尾页\">尾页</A> <a href='#'><font color=red>$page</font>/$totalpage/$total</a>";
    if($totalpage>1){
		return $showpage;
	}
}

?>